/* Perform type name transformation */

#include <cstddef>
#include <cstdlib>

#ifdef __GNUC__
	#include <cxxabi.h>
#endif

#define EXPORT_API

#include <memchart/types.hpp>

#include <memchart/demangle.hpp>

namespace memchart
{
	string demangle (const string & name)
	{
		#ifdef __GNUC__
			int status;

			char *res = abi::__cxa_demangle(name.c_str(), NULL, NULL, &status);

			if (status != 0)
				return "?";
			else
			{
				string s(res);

				std::free(res);

				return s;
			}
		#else
			/* Default implementation */
			return name;
		#endif
	}
}
